/**
 * (C)2012 Exlu Corporation. All rights reserved.
 * 文件名 : cn.exlu.wea.tpk.email.EmailService.java
 * 注意事項   :
 */
package cn.exlu.coco.core.server.email;

import java.util.Properties;

import javax.mail.Session;

/**
 * 邮箱服务器信息设置
 * @author Mark 
 * @version 1.0.1
 * 2013-1-29
 * EmailService.java
 */
public class EmailService {
    private Properties properties=new Properties();
    public EmailService(){
        init();
    }
    private void init(){
        properties.put("mail.smtp.auth", true);
    }

    /**
     * 获得smtpAddress
     * @return smtpAddress
     */
    public String getSmtpAddress() {
        return properties.getProperty("mail.smtp.host");
    }
    /**
     * 设置smtpAddress
     * @param smtpAddress smtpAddress
     */
    public void setSmtpAddress(String smtpAddress) {
        properties.put("mail.smtp.host", smtpAddress);
    }
    /**
     * 获得smtpPort
     * @return smtpPort
     */
    public String getSmtpPort() {
        return properties.getProperty("mail.smtp.port");
    }
    /**
     * 设置smtpPort
     * @param smtpPort smtpPort
     */
    public void setSmtpPort(String smtpPort) {
        properties.put("mail.smtp.port", smtpPort);
    }
    /**
     * 获得pop3Address
     * @return pop3Address
     */
    public String getPop3Address() {
        return properties.getProperty("mail.pop3.host");
    }
    /**
     * 设置pop3Address
     * @param pop3Address pop3Address
     */
    public void setPop3Address(String pop3Address) {
        properties.put("mail.pop3.host", pop3Address);
    }
    /**
     * 获得pop3Port
     * @return pop3Port
     */
    public String getPop3Port() {
        return properties.getProperty("mail.pop3.port");
    }
    /**
     * 设置pop3Port
     * @param pop3Port pop3Port
     */
    public void setPop3Port(String pop3Port) {
        properties.put("mail.pop3.port", pop3Port);
    }
    /**
     * 获得isAuth
     * @return isAuth
     */
    public boolean isAuth() {
        return (Boolean)properties.get("mail.smtp.auth");
    }
    /**
     * 设置isAuth
     * @param isAuth isAuth
     */
    public void setAuth(boolean isAuth) {
        properties.put("mail.smtp.auth", isAuth);
    }
    /**
     * 获得properties
     * @return properties
     */
    public final Properties getProperties() {
        return properties;
    }
    
    public final EmailConnection createEmailConnection(LoginAuthentication loginAuth){
        Session session;
        if (isAuth()) {
            session = Session.getInstance(properties, loginAuth);
        } else {
            session = Session.getInstance(properties);
        }
        return new EmailConnection(session);
    }
}
